package controllers;

import helpers.IdUniqueHelper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

import data.Data;
import data.EmailData;
import entities.Email;

public class Test2 {
	public static void main(String[] args) throws IOException {
		
		DBCollection coll = Data.list(); //sendMailHatforrent
		
		int numstart = 270016;
		
		DBCursor cursor = coll.find().skip(numstart);
		while (cursor.hasNext()) {
			DBObject dbObject = (DBObject) cursor.next();
			
			if (dbObject!= null && !EmailData.checkEmailExists((String) dbObject.get("email"))) {
			
				BasicDBObject email = new BasicDBObject("_id", IdUniqueHelper.getId()).
							append("email", (String) dbObject.get("email")).
							append("status", 1).
							append("created", (new Date()).toString());	
				
				EmailData.insert(email);
				System.out.println(numstart + cursor.numSeen() + " - Add success " + (String) dbObject.get("email") + " success.");
			} else {
				System.out.println(numstart + cursor.numSeen() + " - Email " + (String) dbObject.get("email") + " has been exists");
			}
			
		}				
		
		/*BasicDBObject email = new BasicDBObject("_id", IdUniqueHelper.getId()).
        						append("email", "hoanbn1984@gmail.com").
        						append("status", 1).
        						append("created", (new Date()).toString());						
		EmailData.insert(email);*/
		
		/*List<DBObject> emails = EmailData.list();
		
		for (DBObject email : emails) {
			System.out.println(email.get("email"));
		}
		*/
		
		/*DBObject email = EmailData.getByEmail("hoantocxoan1@gmail.com");
		if (email != null) {
			System.out.println(email.get("email"));
		}*/
		
		//EmailData.delete("EEI7029UK");
	}
}
